package com.ewo.controller.ApplicationPageController;

import com.ewo.entity.ApplicationPage.CustomerInformation;
import com.ewo.entity.ResponseResult;
import com.ewo.service.ApplicationPage.CustomerInformationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
public class CustomerInformationController {

    @Resource
    CustomerInformationService customerInformationService;


    @GetMapping("/listUserInfo")
    public ResponseResult findAllCustomerInformation() {
        List<CustomerInformation> customerInformationList = customerInformationService.findAllCustomerInformation();
        if (customerInformationList != null && customerInformationList.size() != 0) {
            return ResponseResult.ok(customerInformationList);
        }
        return ResponseResult.fail();
    }

    //根据员工id查找关联用户
    @GetMapping("/cinfo/{empId}")
    public ResponseResult findCustomerInformationByEmp(@PathVariable int empId){
        System.out.println("当前登录员工id"+empId);
        List<CustomerInformation> customerInformationList = customerInformationService.findCustomerInformationByEmp(empId);
        if (customerInformationList != null && customerInformationList.size() != 0) {
            return ResponseResult.ok(customerInformationList);
        }
        return ResponseResult.fail();
    }


    //查询单个用户信息
    @GetMapping("/findUserInfo/{name}")
    public ResponseResult findCustomerInformationByName(@PathVariable("name") String name) {
        CustomerInformation customerInformation = customerInformationService.findCustomerInformationByName(name);
        return customerInformation == null ? ResponseResult.ok(customerInformation):ResponseResult.fail();
    }

    //查询用户id查找单个用户信息
    @GetMapping("/findCidInfo/{cid}")
    public ResponseResult findCustomerInformationByName(@PathVariable("cid") int cid) {
        CustomerInformation customerInformation = customerInformationService.findCustomerInformationByCid(cid);
        return customerInformation == null ? ResponseResult.ok(customerInformation):ResponseResult.fail();
    }

}
